<?php
require './gaomysql.php';
$m = new Model();
$action = $_GET['a'];
switch($action) {
    case 'list':
        $list = $m->find('wm_bbs_bbs','','');
        foreach ($list as $k=>$v){

           $list[$k]['times'] = date("Y-m-d H:i:s",$v['bbs_time']);
            $lists = $m->find('wm_user_user','user_id',$v['user_id']);
            foreach ($lists as $key=>$vo){
                $list[$k]['user_head'] = $vo['user_head'];
                $list[$k]['user_nickname'] = $vo['user_nickname'];
            }
        }
        if($list){
            echo json_encode($list);
        }else{
            echo json_encode('暂无数据！');
        }

        break;
    case 'inst':
        $id = $_POST['id'];// 发帖人id

        $title = $_POST['title'];//标题

        $content = $_POST['content'];//内容
        $time = time();//发帖时间

        if(!$title || !$content){
            echo json_encode('请检查帖子标题和内容！');
        }else{
            $list = $m->ins('wm_bbs_bbs','user_id,bbs_title,bbs_content,bbs_time',"$id,$title,$content,$time");
            if($list){
                echo json_encode('发帖成功！');
            }else{
                echo json_encode('发帖失败！');
            }
        }

        break;
    case 'xiangqing':
        $id = $_POST['tid'];// 帖子id
        $list = $m->find('wm_replay_replay','replay_cid',$id);
        foreach ($list as $k=>$v){
            $list[$k]['timess'] = date("Y-m-d H:i:s",$v['replay_time']);
            $lis = $m->find('wm_user_user','user_id',$v['replay_uid']);
            foreach ($lis as $ke=>$vos){
                $list[$k]['user_head'] = $vos['user_head'];
            }
        }

        $lists = $m->find('wm_bbs_bbs','bbs_id',$id);
        foreach ($lists as $k=>$v){
            $lists[$k]['times'] = date("Y-m-d H:i:s",$v['bbs_time']);

            $listss = $m->find('wm_user_user','user_id',$v['user_id']);
            foreach ($listss as $key=>$vo){
                $lists[$k]['user_head'] = $vo['user_head'];
                $lists[$k]['user_nickname'] = $vo['user_nickname'];
            }
        }
        if($list){
            $data = ['huifu'=>$list,'louzhu'=>$lists];
            echo json_encode($data);
        }else{
            $data =['louzhu'=>$lists];
            echo json_encode($data);
        }
        break;
    case 'pinglun':
        $replay_cid = $_POST['replay_cid'];// 评论帖子id
        $replay_module= 'bbs';
        $replay_uid=$_POST['replay_uid'];//用户id
        $replay_content = $_POST['replay_content'];
        $replay_time = time();

       if(!$replay_content){
           echo json_encode('请填写评论内容！');
       }else{
           $list = $m->ins('wm_replay_replay','replay_cid,replay_module,replay_uid,replay_content,replay_time',"$replay_cid,$replay_module,$replay_uid,$replay_content,$replay_time");
           if($list){
               echo json_encode('评论成功！');
           }else{
               echo json_encode('评论失败！');
           }
       }

        break;
    case 'shetuans':

        $list = $m->find('wm_user_finance','finance_types','个人');
        $arr = Array();
        if($list){
            foreach ($list as $k=>$v){
                $lists = $m->find('wm_user_user','user_id',$v['finance_user_id']);
                $arr[] = $lists;
             }
            echo json_encode($arr);
        }else{
            echo json_encode('暂无数据');
        }
        break;
    default:
        break;
}
?>